package com.zhihui.kafka;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.integration.support.MessageBuilder;

/**
 * Created by hengxing on 2017/9/13.
 */
@EnableBinding(MsgChannel.class)
public class SendService {

    @Autowired
    MsgChannel msgChannel;

    public void sendMessage(String msg) {

        try {
            msgChannel.sampleSink().send(MessageBuilder.withPayload(msg).build());

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @StreamListener(MsgChannel.sampleSink)
    public void messageSink(Object payload) {
        System.out.println("Received: " + payload);
    }


}
